import User from "../model/user.model.js";
export async function createdUser(userName, passWord) {
  try {
    const res = await User.create({ userName, passWord });
    return res;
  } catch (err) {
    return err;
  }
}

export async function getUserInfo({ userName, id, isAdmin }) {
  const whereOb = {};
  if (id) {
    whereOb.id = id;
  }
  if (userName) {
    whereOb.userName = userName;
  }
  if (isAdmin) {
    whereOb.isAdmin = isAdmin;
  }

  try {
    const res = await User.findOne({
      attributes: ["id", "userName", "isAdmin", "passWord"],
      where: whereOb,
    });

    return res?.dataValues || null;
  } catch (err) {
    return err;
  }
}
